package com.aboverock.common.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * The Class NotContainsValidator.
 *
 * @author Rock Wang
 */
public class NotContainsValidator implements ConstraintValidator<NotContains, String> {
    private String[] excludes;

    @Override
    public void initialize(NotContains constraintAnnotation) {
        excludes = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        for (String exclude : excludes) {
            if (value.contains(exclude)) {
                return false;
            }
        }
        return true;
    }

}
